package com.leetcode.offer;

/**
 * @author `RKC`
 * @date 2021/10/14 8:10
 */
public class Offer69山峰数组的顶部 {

    public static int peakIndexInMountainArray(int[] arr) {
        //山峰的左边单调递增，山峰的右边单调递减
        //肯定不是0和arr.length-1
        int left = 1, right = arr.length - 2;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (arr[mid] > arr[mid - 1]) left = mid + 1;
            else right = mid - 1;
        }
        return right;
    }

    public static void main(String[] args) {
        int[] arr = {24, 69, 100, 99, 79, 78, 67, 36, 26, 19};
        System.out.println(peakIndexInMountainArray(arr));
    }
}
